#题目链接 https://leetcode.cn/problems/flood-fill/
class Solution:
    def floodFill(self, image: List[List[int]], sr: int, sc: int, color: int) -> List[List[int]]:
        if image[sr][sc] == color:
            return image
        lst = [[sr, sc]]
        org_corlor = image[sr][sc]
        image[sr][sc] = color
        while lst:
            x, y = lst.pop(0)
            nums = [(x+1, y), (x-1, y), (x, y+1), (x, y-1)]
            for m,n in nums:
                if 0<=m<len(image) and 0<=n < len(image[0]) and  image[m][n] == org_corlor:
                    lst.append((m,n))
                    image[m][n] = color
        return image


            